function init() {
  loadFriends();
}

function loadFriends() {
  var req = opensocial.newDataRequest();
  req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER), 'viewer');
  
  var viewerFriends = opensocial.newIdSpec({ "userId" : "VIEWER", "groupId" : "FRIENDS" });
  var opt_params = {};
  opt_params[opensocial.DataRequest.PeopleRequestFields.MAX] = 100;
  req.add(req.newFetchPeopleRequest(viewerFriends, opt_params), 'viewerFriends');

  req.send(onLoadFriends);
}


function onLoadFriends(data) {
  html = new Array();

	  var viewer = data.get('viewer').getData();
	  var viewerFriends = data.get('viewerFriends').getData();
	if(viewerFriends == null)
	{
		html.push('<center>You have no friends</center>');
	}
	else {
		
	  html.push('<ul>');
	  viewerFriends.each(function(person) {
	    if (person.getId()) {
	      html.push('<li>' + person.getDisplayName() + "</li>");
	    }
	  });
	  html.push('</ul>');
  	}
	  document.getElementById('friends').innerHTML = html.join('');
}

